﻿using System;
using System.Xml.Serialization;

namespace Our.Umbraco.UniversalMediaPicker.Providers.TwitPic.Model
{
	[XmlRoot("image")]
	public class TwitPicImage
	{
		private const string BASE_URL = "http://twitpic.com/";

		/// <summary>
		/// Initializes a new instance of the <see cref="TwitPicImage"/> class.
		/// </summary>
		public TwitPicImage()
		{
		}

		[XmlElement("id")]
		public string Id { get; set; }

		[XmlElement("short_id")]
		public string ShortId { get; set; }

		[XmlElement("user_id")]
		public string UserId { get; set; }

		[XmlElement("source")]
		public string Source { get; set; }

		[XmlElement("message")]
		public string Message { get; set; }

		[XmlElement("views")]
		public int Views { get; set; }

		[XmlElement("width")]
		public int Width { get; set; }

		[XmlElement("height")]
		public int Height { get; set; }

		[XmlElement("size")]
		public int Size { get; set; }

		[XmlElement("type")]
		public string Type { get; set; }

		[XmlElement("timestamp")]
		public string Timestamp { get; set; }

		public string ImageMiniUrl
		{
			get
			{
				return string.Concat(BASE_URL, "show/mini/", this.ShortId);
			}
		}

		public string ImageThumbnailUrl
		{
			get
			{
				return string.Concat(BASE_URL, "show/thumb/", this.ShortId);
			}
		}

		public string Url
		{
			get
			{
				return string.Concat(BASE_URL, this.ShortId);
			}
		}

		/// <summary>
		/// Returns a <see cref="System.String"/> that represents this instance.
		/// </summary>
		/// <returns>
		/// A <see cref="System.String"/> that represents this instance.
		/// </returns>
		public override string ToString()
		{
			return string.Format("<a href='{0}' class='twitpic'><img src='{1}' alt='{2}' /></a>", this.Url, this.ImageThumbnailUrl, this.Message);
		}
	}
}
